package com.yoyo.ad.utils;

import android.content.Context;

import com.yoyo.ad.gen.DaoMaster;
import com.yoyo.ad.gen.DaoSession;


public class GreenDaoManager {
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    private Context mContext;
    private static GreenDaoManager instance;

    /**
     * 静态内部类，实例化对象使用
     */
//    private static class SingleInstanceHolder {
//        private static final GreenDaoManager INSTANCE = new GreenDaoManager();
//    }

    /**
     * 对外唯一实例的接口
     */
//    public static GreenDaoManager getInstance() {
//        return SingleInstanceHolder.INSTANCE;
//    }

    public static GreenDaoManager getInstance() {
        if (instance == null) {
            synchronized (GreenDaoManager.class) {
                if (instance == null) {
                    instance = new GreenDaoManager();
                }
            }
        }
        return instance;
    }

    /**
     * 初始化数据
     */
    public void init(Context context) {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(context,
                "yoyosdk");
        mDaoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
        mDaoSession = mDaoMaster.newSession();
    }

//    public DaoMaster getDaoMaster() {
//        return mDaoMaster;
//    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public DaoSession getNewSession() {
        mDaoSession = mDaoMaster.newSession();
        return mDaoSession;
    }
}